"""
Author : sunshicheng
DateTime : 2021/6/4.3:57 下午
FileName : locust_built_in.py
Desc: 内部函数的使用,初始化操作
"""
import sys
from locust import HttpUser, TaskSet, constant, task

sys.path.append('..')
from config.base_info import Static_info as si
from config.user_token import Token

token = Token('18226287291')
headers = token.test_token()


class MyTask(TaskSet):
    def on_start(self):
        print(1)

    @task
    def test_get(self):
        data = {
            "account": "sunshicheng"
        }
        with self.client.get(si.inter['saas']['saas_permission'], params=data, headers=headers,
                             name='获取用户权限', catch_response=True) as result:
            if 'SUCCESS。' in result.text:
                result.success()
            else:
                # 错误信息可以自己定义
                result.failure(str(result.text))

    def on_stop(self):
        print(2)


class MyUsers(HttpUser):
    def on_start(self):
        print(3)

    tasks = [MyTask]
    wait_time = constant(0.1)

    def on_stop(self):
        print(4)
